﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Warehouse.Domain;
using Warehouse.Domain.DTO;
using Warehouse.Read.API.Applcation.Command.EnterStoragesCommand;
using Warehouse.Read.API.Applcation.Command.InventoryListCommand;
using Warehouse.Read.API.Applcation.Command.WarehouseCommand;
using Warehouse.Read.API.Dtos;

namespace Warehouse.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class EnterStoragesController : ControllerBase
    {
        protected readonly IMediator _mediator;

        public EnterStoragesController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 查询分页
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<EnterStoragesSelectDtos>> GetWarehouseList([FromQuery] EnterStoragesSelectCommand command)
        {
            ApiResult<EnterStoragesSelectDtos> result = new ApiResult<EnterStoragesSelectDtos>();
            try
            {
                var sid = HttpContext.User.FindFirst(JwtRegisteredClaimNames.Sid)?.Value;//获取公司id
                command.office_id = sid;
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 查询分页
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<EnterStoragesSetDto>> GetEntsrStoragesList([FromQuery] EnterStoragesSetCommand command)
        {
            ApiResult<EnterStoragesSetDto> result = new ApiResult<EnterStoragesSetDto>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 查询分页报表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<InventoryListSelectDto>>> GetWearthList([FromQuery]InventoryListSelectCommand command)
        {
            ApiResult<List<InventoryListSelectDto>> result = new ApiResult<List<InventoryListSelectDto>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
